package system

import (
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
	"go.uber.org/zap"
	"new_club_recruitment/global"
	common "new_club_recruitment/model/common/request"
	"new_club_recruitment/model/common/response"
)

// Login 登陆
func (b *BaseApi) Login(c *gin.Context) {
	var info common.Info
	if err := c.ShouldBind(&info); err != nil {
		errs, ok := err.(validator.ValidationErrors)
		if !ok {
			response.Fail(c)
			return
		}
		response.FailWithMessage(errs.Translate(global.GAV_TRANS), c)
		return
	}
	//2.处理业务
	if data, url, err := userService.Login(info); err != nil {
		global.GVA_LOG.Error("登陆失败!", zap.Error(err))
		response.Fail(c)
	} else {
		//3.返回响应
		response.OkWithDetailed(gin.H{"admin": data, "url": url}, "登陆成功", c)
	}
}
